﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Web.API.IBLL;
using Web.API.IDAL;
using Web.API.Model;

namespace Web.API.BLL
{
    public class StaffBll:StaffIBLL
    {
        public StaffBll(UserIDAL<StaffModel> dal, UserIDAL<StaffTypeModel> dAl) 
        {
            Dal = dal;
            DAl = dAl;
        }
        public UserIDAL<StaffModel> Dal { get; }
        public UserIDAL<StaffTypeModel> DAl { get; }

        public Task<int> AddStaff(StaffModel staff)
        {
           return Dal.AddAsync(staff);
        }

        public  dynamic GetStaff(string? name, int stafftypeid)
        {
            var list = from a in Dal.GetAll()
                       join b in DAl.GetAll() on a.StaffTypeId equals b.StaffTypeId
                       select new
                       {
                           a.Id,
                           a.Name,
                           a.Sex,
                           a.StaffCard,
                           a.Phone,
                           a.Addr,
                           a.StaffTypeId,
                          StaffType= b.Name
                       };
            if (!string.IsNullOrEmpty(name))
            {
                list = list.Where(x=>x.Name.Contains(name));
            }
            if (stafftypeid > 0)
            {
                list = list.Where(x=>x.StaffTypeId==stafftypeid);
            }
            return list;
        }

        public List<StaffModel> GetStaffModels()
        {
           return Dal.GetAll().ToList();
        }

        public List<StaffTypeModel> Xialak()
        {
           return DAl.GetAll().ToList();
        }
    }
}
